/**
 * @author Just、倾城
 * @created 2025-11-04
 * @description
 *
 */
public class MorningPricingHandler implements PricingHandler{
    private PricingHandler next;

    @Override
    public double handleRequest(double distance, String time, String taxiType) {
        // 解析时间
        int hour = Integer.parseInt(time.split(":")[0]);
        if (hour >= 6 && hour < 12) {
            return calculatePrice(distance, taxiType);
        }
        // 传递给下一个处理器
        if (next != null) {
            return next.handleRequest(distance, time, taxiType);
        }
        throw new IllegalArgumentException("无法确定计价策略");
    }

    private double calculatePrice(double distance, String taxiType) {
        double pricePerKm = taxiType.equals("A") ? 8.0 : 6.0;
        return distance * pricePerKm;
    }

    @Override
    public void setNext(PricingHandler next) {
        this.next = next;
    }
}
